package com.example.demo2;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RequestMapping("/message")
@RestController
public class MessageController {
    private List<MessageInfo> message=new ArrayList<>();
    @RequestMapping(value = "/publish",produces = "application/json")
    public String publish(@RequestBody MessageInfo messageInfo){
        if(!StringUtils.hasLength(messageInfo.getMessage())||
                !StringUtils.hasLength(messageInfo.getTo())||
               !StringUtils.hasLength(messageInfo.getFrom())){
            return "{\"ok\":0}";
        }
            message.add(messageInfo);
            return "{\"ok\":1}";
    }
    @RequestMapping("/getlist")
    public List<MessageInfo> getlist(){
        return message;
    }
}
